/*

	This file collpases the BACI data to the destination-product year level

*/


cd ${work}4_reg_variables

use input\baci, clear

*EXCL. DK AS EXPORTING COUNTRY
drop if i==208

*INCL. ONLY SAMPLE DESTINATIONS AS IMPORTING COUNTRY
rename j code
merge m:1 code using input\country_codes_baci, keep(3) keepusing(land) nogen
merge m:1 land using output\sample_d , keep(2 3) keepusing(land)
qui count if _m==2
assert r(N)==1
assert land=="LU" if _m==2
drop if _m==2
drop _m

*COLLAPSE
rename t year
rename k cn6
collapse (sum) value=v , by(land cn6 year)

compress
save output\baci_pdt, replace